package pub.guoxin.oops.common.protocol.config;

import lombok.Getter;
import pub.guoxin.oops.common.protocol.entity.map.DataProtocolCodeMap;
import pub.guoxin.oops.common.protocol.entity.map.DataProtocolCommandMap;
import pub.guoxin.oops.common.protocol.entity.map.DataProtocolTypeMap;

/**
 * Created by guoxin on 18-3-20.
 */
@Getter
public abstract class DataProtocolConfigurerAdapter {

    private DataProtocolCodeMap dataProtocolCodeMap;

    private DataProtocolTypeMap dataProtocolTypeMap;

    private DataProtocolCommandMap dataProtocolCommandMap;

    public abstract DataProtocolCodeConfigurer register(DataProtocolCodeConfigurer configurer);

    public abstract DataProtocolTypeConfigurer register(DataProtocolTypeConfigurer configurer);

    public abstract DataProtocolCommandConfigurer register(DataProtocolCommandConfigurer configurer);

    private void register0(DataProtocolCodeConfigurer configurer) {
        configurer.getAdapters().forEach(adapter -> dataProtocolCodeMap.putAll(adapter.build()));
    }

    private void register0(DataProtocolTypeConfigurer configurer) {
        configurer.getAdapters().forEach(adapter -> dataProtocolTypeMap.putAll(adapter.build()));
    }

    private void register0(DataProtocolCommandConfigurer configurer) {
        configurer.getAdapters().forEach(adapter -> dataProtocolCommandMap.putAll(adapter.build()));
    }

}
